<?php

namespace App\Http\Controllers;

use App\Events\Event;
use App\Events\ExampleEvent;
use App\Events\Message;
use App\Events\TestEvent;
use App\Jobs\TestJob;
use App\Models\Products\Product;
use App\Services\Products\ProductService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use PHPUnit\Util\Test;

class UsersController extends Controller
{
    public function getBroad() {

        broadcast(new Message("广播消息"));
    }

    public function getQueue() {
        $data = [
            'user_id' => 1,
            'room_id' => 1,
            'key' => '123456',
            'status' => 1
        ];
        dispatch(new TestJob($data));
        echo 11;
    }

    public function getEvent() {
        $data = [
            'user_id' => 1,
            'room_id' => 1,
            'key' => '123456',
            'status' => 1
        ];
        $event = new TestEvent($data);
        echo 22;
        event($event);exit();
    }


    public function info(){
        $name = $this->_request->input('name');
        $id = $this->_request->input('id');

        $data = ProductService::getProducts();
        $data['name'] = $name;
        $data['id'] = $id;
        /*$db = DB::table("catalog_product_entity");
        //$data = $db->where('entity_id','>',2)->get();

        //$data = $db->where('entity_id', 1)->first();
        //$data = $db->orderBy('entity_id','desc')->get();
        $data = $db->limit(3)->offset(1)->get();*/
        return $this->_outPut($data, 1, 'ok');
    }


    public function create()
    {

        $redis = app('redis');
        $redis->set('aabb',11);
        return $redis->get('aabb');

        $access_token = 'bb';
        $value = 20;
        // 缓存是否存在
        if (app ('cache' )->has ( $access_token )) {
            // 获取缓存
            $accessAppId = app ( 'cache' )->get ( $access_token );
            var_dump($accessAppId);die;
        } else {
            // 保存缓存，并且设置为120分钟失效
            app('cache')->put($access_token, $value, 120);
        }




        $data = [
            'aa'=>11,
            'bb'=>22
        ];
        return response()->json(['code'=>1,'msg'=>'ok','data'=>$data]);
    }

    public function show()
    {
        echo 11;
    }
}
